package com.hp.attendance.service;

import com.hp.attendance.dao.DepartmentDao;
import com.hp.attendance.entity.Department;
import com.hp.attendance.entity.Menu;
import com.hp.attendance.entity.PageInfo;
import com.hp.attendance.entity.dto.MenuDto;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class DepartmentService {
    private DepartmentDao departmentDao = new DepartmentDao();

    public PageInfo<Department> getDepartmentList(int pageNo , int pageSize) throws SQLException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
        PageInfo<Department> page = new PageInfo<Department>();
        //查询分页的数据                           2       10
        List<Department> list = departmentDao.getDepartmentList(pageNo, pageSize);

        page.setRecords(list);
        //查询总记录条数
        long total = departmentDao.getTotal();
        page.setTotal(total);
        //设置当前页码
        page.setCurrent(pageNo);
        //设置总页数
        int pages = (int)Math.ceil(total / (pageSize * 1.0));
        page.setPages(pages);
        return page;
    }
    public void DepartmentAdd(Department department) throws SQLException, IOException, ClassNotFoundException {
       departmentDao.DepartmentAdd(department);
    }

    public Department getDepartmentMAX() throws SQLException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
        return departmentDao.getDepartmentMAX();
    }
    public void DepartmentDel(int id) throws SQLException, IOException, ClassNotFoundException {
       departmentDao.DepartmentDel(id);
    }
    public void DepartmentUpdate(Department department) throws SQLException, IOException, ClassNotFoundException {
       departmentDao.DepartmentUpdate(department);
    }
    public Department departmentPreUpd(int id) throws SQLException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
       return departmentDao.departmentPreUpd(id);
    }

    public List<Department> getList() throws SQLException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
        return departmentDao.getList();
    }
}
